﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WorldGroupBuilder
{
    public partial class WorldGroupBuilder : Form
    {
        public WorldGroupBuilder()
        {
            InitializeComponent();
        }

        private void world_add_Click(object sender, EventArgs e)
        {
            if (this.world_id.Text != string.Empty)
            {
                AddNewWorld(int.Parse(this.world_id.Text));
            }
        }

        private void world_del_Click(object sender, EventArgs e)
        {
            DelWorld();
        }

        private void world_join_Click(object sender, EventArgs e)
        {
            JoinGroup();
        }

        private void world_free_Click(object sender, EventArgs e)
        {
            FreeWorld();
        }

        private void group_del_Click(object sender, EventArgs e)
        {
            DelGroup();
        }

        private void group_add_Click(object sender, EventArgs e)
        {
            AddNewGroup();
        }

        private void group_list_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (group_list.SelectedItem != null)
               ShowGroup((int)group_list.SelectedItem);
        }

        private void Save_Click(object sender, EventArgs e)
        {
            SaveFileDialog sfd = new SaveFileDialog();
            sfd.InitialDirectory = ".\\";
            if (sel_gs.Checked == true)
                sfd.Filter = "GameServerGroup(*.gsg)|*.gsg";
            else if (sel_ps.Checked == true)
                sfd.Filter = "PosServerGroup(*.psg)|*.psg";
            else
                return;
            sfd.RestoreDirectory = true;
            sfd.FilterIndex = 1;
            if (sfd.ShowDialog() == DialogResult.OK)
            {
                SaveFile(sfd.FileName);
            }
        }

        private void Open_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.InitialDirectory = ".\\";
            ofd.Filter = "GameServerGroup(*.gsg)|*.gsg|PosServerGroup(*.psg)|*.psg";

            ofd.RestoreDirectory = true;
            ofd.FilterIndex = 1;
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                ClearAll();
                ReadFile(ofd.FileName);
                foreach (int id in m_groupList)
                {
                    group_list.Items.Add(id);
                }
            }
        }

        private void New_Click(object sender, EventArgs e)
        {
            ClearAll();
        }
    }
}
